﻿#region

using System.Collections.Generic;
using System.Linq;

#endregion

namespace Domain.Algorithms {
    public static class GraphUtils<TEdge> where TEdge : IEdge, new() {
        public static List<Vertex> Neighbourhood(Graph<TEdge> graph, Vertex vertex) {
            var vertices = new List<Vertex>();
            foreach (var edge in graph.Edges) {
                if (!edge.Vertices.Contains(vertex)) {
                    continue;
                }
                foreach (var v in edge.Vertices.Where(v => v != vertex)) {
                    if (vertices.Contains(v)) {
                        continue;
                    }
                    vertices.Add(v);
                }
            }
            return vertices;
        }

        public static bool IsIncluded(IEnumerable<Vertex> vertices1, ICollection<Vertex> vertices2) {
            foreach (var vertex in vertices1) {
                if (!vertices2.Contains(vertex)) {
                    return false;
                }
            }
            return true;
        }
    }
}